// 对数据库进行配置的文件
var mongoose = require('mongoose')

mongoose.connect('mongodb://localhost:27017/pdd')

mongoose.connection.on('open', () => {
    console.log('连接成功')
}).on('error', () => {
    console.log('连接失败')
})

// 用户表
var userShema = new mongoose.Schema({
    username: String,
    psw: String,
    phone1: Number,
    email: String
})
var addressShema = new mongoose.Schema({
    phone1: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'user'
    },
    cons: String,
    constel: Number,
    city: String,
    email: String,
    dele: String

})
// var 
// 图书表
var itemShema = new mongoose.Schema({
    add1: String,
    add2: String,
    add3: String,
    iname: String,
    iprice: Number,
    icurrent: String,
    icurrent1: String,
    iimg: String,
    iid: String,
    inum: Number,
    user: String,
    pay: String
})
var CartShema = new mongoose.Schema({
    ids: String,
    name: String,
    price: Number,
    price_1: Number,
    img: String,
    user: String
})
var jsonShema = new mongoose.Schema({
    data: Array,
    goods_list: Array
})
var imgshema = new mongoose.Schema({
    imgurl: String,
    iduser: String
})
var User = mongoose.model('user', userShema)

var address = mongoose.model('address', addressShema)
// var ite = mongoose.model('json', bookShema)
var car = mongoose.model('car', CartShema)
var item = mongoose.model('item', itemShema)
var json1 = mongoose.model('json', jsonShema)
var img = mongoose.model('img', imgshema)
module.exports = { User, address, item, json1, img, car }